//
//  BHMeUserFunServiceManager.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/8/18.
//

import UIKit

class BHMeUserFunServiceManager {
    var funId: String = ""
    
    // 主详情接口的回调
    var responseForMainDetailBlock:((Bool,String,BHUserFunApplyDetailModel) -> Void)?
    // 报名用户修改用户报名信息 || 退出趣玩 || 移除报名用户 || 解散趣玩
    /**
     0 修改信息
     1 退出趣玩
     2 移除报名用户
     3 解散趣玩
     */
    var responseForCompleteHandlerBlock:((Bool,String,Int) -> Void)?
    
    
    func queryApplyDetailService()  {
        var dic: [String:Any] = [:]
        dic["id"] = self.funId
        dic["longitude"] = BHLocationManager.shared.longitude
        dic["latitude"] = BHLocationManager.shared.latitude
        
        SVProgressHUD.show()
        let manager = BHHTTPClient.init()
        manager.get(url: String.me_fun_apply_detail_url, paramters: dic) { (success, errorMsg, responseDic) in
            SVProgressHUD.dismiss()
            let model = BHUserFunApplyDetailModel.init()
            if success == true {
                let resultDic = BHJsonTool.decodeDicFromDic(dic: responseDic, key: "result")
                model.parseDic(resultDic)
            }
            
            self.responseForMainDetailBlock?(success,errorMsg,model)
        }
    }
    
    func editeApplyInfoService(signupId: String,name: String,phone: String)  {
        var dic: [String:Any] = [:]
        dic["id"] = signupId
        dic["name"] = name
        dic["phone"] = phone
        
        let manager = BHHTTPClient.init()
        manager.put(url: String.me_fun_applyUser_edite_url, paramters: dic) { (success, errorMsg, responseDic) in
            self.responseForCompleteHandlerBlock?(success,errorMsg,0)
        }
    }
    
    
    func userQuiteService(signupId: String)  {
        var dic: [String:Any] = [:]
        dic["id"] = signupId
        
        let manager = BHHTTPClient.init()
        manager.post(url: String.me_fun_applyUser_quite_url, paramters: dic) { (success, errorMsg, responseDic) in
            self.responseForCompleteHandlerBlock?(success,errorMsg,1)
        }
    }
    
    
    
    func createrRemoveUserService(userId: String)  {
        var dic: [String:Any] = [:]
        dic["userId"] = userId
        dic["goplayId"] = self.funId
        
        let manager = BHHTTPClient.init()
        manager.post(url: String.me_fun_creater_removeUser_url, paramters: dic) { (success, errorMsg, responseDic) in
            self.responseForCompleteHandlerBlock?(success,errorMsg,2)
        }
    }
    
    
    func createrDissolveFunService()  {
        var dic: [String:Any] = [:]
        dic["goplayId"] = self.funId
        
        let manager = BHHTTPClient.init()
        manager.post(url: String.me_fun_creater_dissolve_url, paramters: dic) { (success, errorMsg, responseDic) in
            self.responseForCompleteHandlerBlock?(success,errorMsg,3)
        }
    }
    
}
